home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18262 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  55 lines

  1. Path: cville-srv.wam.umd.edu!sartoris
  2. From: meade@inforum.umd.edu (Douglas S. Meade)
  3. Newsgroups: comp.lang.c++
  4. Subject: Printf behavior in Borland C++
  5. Date: Fri, 19 Apr 96 17:33:06 GMT
  6. Organization: INFORUM
  7. Message-ID: <4l8ipp$km1@cville-srv.wam.umd.edu>
  8. NNTP-Posting-Host: sartoris.umd.edu
  9. Summary: Behavior of printf different in BC 3.1 and BC 4.5
  10. Keywords: Borland, printf
  11. X-Newsreader: News Xpress Version 1.0 Beta #3
  12.  
  13. I have a question about the behavior of the printf function with
  14. small negative numbers in Borland C++ 3.1 versus the same function
  15. in Borland C++ 4.x.
  16.  
  17. The following simple program shows the problem:
  18.  
  19. ________________________________________________________
  20. #include <stdio.h>
  21. #include <conio.h>
  22.  
  23. void main() {
  24. float i, j;
  25. i=-0.000001;
  26. printf("i is (printed by %%10.3f) %10.3f\n",i);
  27. printf("i is (printed by %%10.7f) %10.7f\n",i);
  28. return;
  29. }
  30. ________________________________________________________
  31.  
  32. In Borland C++ 3.1, the output is:
  33.  
  34. i is (printed by %10.3f)     -0.000
  35. i is (printed by %10.7f) -0.0000010
  36.  
  37.  
  38.  
  39. In Borland C++ 4.5:
  40.  
  41. i is (printed by %10.3f)      0.000
  42. i is (printed by %10.7f) -0.0000010
  43.  
  44.  
  45. My question is: Why is the negative sign getting swallowed in the
  46. %10.3f printf in BC4?  Is this considered the correct C++ behavior?
  47.  
  48. I've tested this with BC++ for OS/2 version 2.0, and it yields the
  49. same results as BC4.5.  I haven't tested it with Watcom, Microsoft,
  50. or other compilers.
  51.  
  52. Any help would be appreciated.
  53.  
  54. Douglas Meade
  55.